<include file="header"/>
<link rel="stylesheet" href="/assets/public/mobiscroll/css/mobiscroll.custom-3.0.0-beta2.min.css">
<div class="wraper space">
	<div class="list-info status tb-mode">
		<p class="tb-cell"><span class="iconfont icon-location"></span></p>
		<div class="tb-cell">
			{BEESCRM:$data.order.username}&nbsp;&nbsp;&nbsp;&nbsp;
			{BEESCRM:$data.order.mobile}&nbsp;&nbsp;&nbsp;&nbsp;
			{BEESCRM:$data.order.address}
		</div>
	</div>
    <div class="order-list">
        <a href="{BEESCRM::U('base/store/index',array('store_id'=>$storeId))}" class="shop">
        	<span class="iconfont icon-dianpu"></span>
        	{BEESCRM:$data.store_name} <span class="iconfont icon-you"></span>
        </a>
		<volist name="data['order']['StoreOrderGoods']" id="vo">
			<a href="#" class="list-info order text-black">
				<div class="tb-cell product-img">
					<div><img src="{BEESCRM:$vo.goods_thumb}"></div>
				</div>
				<div class="product-info">
					<p>{BEESCRM:$vo.goods_name}</p>
					<p class="prize"><span>￥{BEESCRM:$vo.goods_price}</span> <span>X{BEESCRM:$vo.goods_num}</span></p>
					<p class="text-12">
						<if condition="$data['order']['picked'] eq 1">
							<span class="product-label">自提</span>
							<else/>
							<span class="product-label">快递</span>
						</if>
						<if condition="$browser eq 2">
							<if condition="$data['order']['pay_alipay_id'] neq $alipayId">
								<span class="product-label">厂家直营</span>
							</if>
							<else/>
							<if condition="$data['order']['pay_wechat_id'] neq $wechatId">
								<span class="product-label">厂家直营</span>
							</if>
						</if>
					</p>
					<if condition="$vo['goods_spec'] neq ''">
						<p>规格：{BEESCRM:$vo.goods_spec}</p>
					</if>
				</div>
			</a>
			<if condition="$picked eq 1">
				<div class="list">提取地点：{BEESCRM:$vo.since_address}</div>
				<div class="list">商家规则：{BEESCRM:$vo.picked_rule}</div>
			</if>
		</volist>
    </div>
	<div class="form-list">
		<select id="pay_select">
			<if condition ="$pay_type eq 2">
				<option value="2">支付宝支付</option>
			</if>
			<if condition = "$pay_type eq 1">
				<option value="3">微信支付</option>
			</if>
			<if condition = "$pay_type eq 3">
				<option value="3">校园卡支付</option>
			</if>
		</select>
		<span class="iconfont icon-you"></span>
	</div>

	<div class="order-info">
		<p  class="leave-message" style="background-color: #ffffff;" id="remark">
			买家留言：{BEESCRM:$data.order.remark}
		</p>

		<div class="list">
			<p class="text-right">
				共 <span class="strong-red">{BEESCRM:$data.order.StoreOrderGoods|count}</span> 件商品 &nbsp;&nbsp;&nbsp;
				<!--优惠：<span class="strong-red">￥{BEESCRM:$data.order.discount}</span>-->
			</p>
			<!--<p class="text-right">-->
				<!--合计：<span class="strong-red">￥{BEESCRM:$data.order.order_amount}</span></p>-->
		</div>
	</div>
	<input type="hidden" id="status" value="{BEESCRM:$status}" /><!--校园卡绑定状态-->
    <div class="btn-box bottom clearfix">
        <p class="pull-left"><span class="account">合计：<span>￥{BEESCRM:$data.order.order_amount}</span></span></p>
		<form id="form_campuscard" method="post" action="{BEESCRM:$interface_ip}/{BEESCRM:$interface_name}">
			<input type="hidden" name="tranamt" value="" /><!--交易金额1-->
			<input type="hidden" name="account" value="" /><!--学生账号-->
			<input type="hidden" name="sno" value="" /><!--学工号-->
			<input type="hidden" name="toaccount" value="" /><!--商户账号1-->
			<input type="hidden" name="thirdsystem" value="" /><!--系统注册ID1-->
			<input type="hidden" name="thirdorderid" value="" /><!--第三方订单号1-->
			<input type="hidden" name="ordertype" value="" /><!--接入类型1-->
			<input type="hidden" name="sign" value="" /><!--sign签名-->
			<input type="hidden" name="orderdesc" value="" /><!--商品名称-->
			<input type="hidden" name="praram1" value="" /><!--第三方系统备注字段-->
			<input type="hidden" name="thirdurl" value="" /><!--第三方系统备注字段-->
		</form>	
        <p class="pull-right"><a href="javascript:void(0)" class="btn pay" id="submit">立即付款</a></p>
    </div>
</div>

<include file="commonJs"/>
<script src="/assets/public/mobiscroll/mobiscroll.custom-3.0.0-beta2.min.js"></script>
<script>
	var currYear = (new Date()).getFullYear();
	var opt={};
	opt.date = {preset : 'date'};
	opt.datetime = {preset : 'datetime'};
	opt.time = {preset : 'time'};
	opt.default = {
		theme: 'ios', //皮肤样式
		display: 'bottom', //显示方式
		mode: 'scroller', //日期选择模式
		lang:'zh',
		startYear:currYear - 10, //开始年份
		endYear:currYear + 10 //结束年份
	};

	var optDateTime = $.extend(opt['datetime'], opt['default']);
	var optTime = $.extend(opt['time'], opt['default']);
	$("#date").mobiscroll(optDateTime).datetime(optDateTime);
</script>
<script type="text/javascript">
	$(function(){

		//确认付款
		$(document).on('click','#submit',function(){
			
			var remark=$('#remark').val();
			var order_id = "{BEESCRM:$order_id}";
			var status = $("#status").val();
			var pay_type = $("#pay_select").val();
			
			if(pay_type == 3){
				if(status!=1){
					$.alert('error', '校园卡未绑定,请到个人中心绑定');
					return;
				}
			}
			
			$.ajax({
				url: "{BEESCRM::U('base/store/confirmPay',array('store_id'=>$storeId))}",
				type: 'POST',
				dataType: 'json',
				data: {order_id: order_id,pay_type: pay_type},
				success: function (data) {
					if (data.status == 'AS') {
						location.href = data.url;
					} else if (data.status == 'WS') {
						//微信支付
						if (typeof WeixinJSBridge == "undefined") {
							if (document.addEventListener) {
								document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
							} else if (document.attachEvent) {
								document.attachEvent('WeixinJSBridgeReady', jsApiCall);
								document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
							}
						} else {
							WeixinJSBridge.invoke(
									'getBrandWCPayRequest',
									$.parseJSON(data.url),
									function (res) {
										WeixinJSBridge.log(res.err_msg);
										if (res.err_msg == "get_brand_wcpay_request:ok") {
											paySuccess(data.order_id);
										} else if (res.err_msg == "get_brand_wcpay_request:cancel") {
											$.alert('error', '你肯定不是真的想抛弃我们～');
											return false;
										} else {
											$.alert('error', '哎呀，网络不给力，小微又调皮了，咋们刷新再来一次');
											setTimeout("location.reload()", 2000);
											return false;
										}
									}
							);
						}

					}else if (data.status == 'CampusCard') {
						$("input[name=tranamt]").val(data.data['tranamt']);
						$("input[name=account]").val(data.data['account']);
						$("input[name=sno]").val(data.data['sno']);
						$("input[name=toaccount]").val(data.data['toaccount']);
						$("input[name=thirdsystem]").val(data.data['thirdsystem']);
						$("input[name=thirdorderid]").val(data.data['thirdorderid']);
						$("input[name=ordertype]").val(data.data['ordertype']);
						$("input[name=sign]").val(data.data['sign']);
						$("input[name=orderdesc]").val(data.data['orderdesc']);
						$("input[name=praram1]").val(data.data['praram1']);
						$("input[name=thirdurl]").val(data.data['thirdurl']);
						$("#form_campuscard").attr("action",data.data['interface_url']);
						$("#form_campuscard").submit();
					}else if (data.status == 'S') {
						paySuccess(data.order_id);
					} else {
						swal("", data.message, "error");
					}
				}
			})
		});

		function paySuccess(order_id){
			var json={};
			json.url="{BEESCRM::U('base/store/paysuccess',array('origin'=>$origin,'store_id'=>$storeId))}/order_id/"+order_id;
			$.getAjax(json,false,redirect);
		}

		function redirect(data){
			location.href=data.url;
		}
	});
</script>
<include file="footer" />
